--- @coding utf8

local math_random = math.random

local table_random = function(tab)
    if tab == nil then
        return nil, nil
    end
    local keys = {}
    for k in pairs(tab or {}) do
        keys[#keys + 1] = k
    end
    local key = keys[math.random(#keys)]
    return key, keys[key]
end

local check_if_table_is_array = function(tab)
    if tab == nil then
        return false
    end
    local idx = 1
    for key in pairs(tab) do
        if key ~= idx then
            return false
        end
        idx = idx + 1
    end
    return true
end

local table_copy = function(src)
    local dst = {}
    for field, value in pairs(src or {}) do
        dst[field] = value
    end
    return dst
end

local table_assisn = function(src, dst)
    for field, value in pairs(src or {}) do
        dst[field] = value
    end
end

local function table_deep_copy(src)
    local dst = {}
    for key, value in pairs(src) do
        if type(value) == "table" then
            dst[key] = table_deep_copy(value)
        else
            dst[key] = value
        end
    end
    return dst
end

local t = {a={b=1}}
local t1 = table_deep_copy(t)